package cn.edu.ujn.lab3.controller;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.ujn.lab3.dao.User;
import cn.edu.ujn.lab3.service.IUserService;

@Controller
public class UserController {
	@Autowired
	private IUserService userService;
	//跳转到管理界面
	@RequestMapping("/login.action")
	public String login(String usercode,String password,Model model,HttpSession session) {
		User findUser = this.userService.findUser(usercode, password);
		if(findUser!=null) {
			session.setAttribute("USER_SESSION", findUser);
			//return "customer";
			 return "redirect:customer/list.action";
		}
		model.addAttribute("msg","用户名或密码错误，请重新登录！");
		return "login";
	}
	
	//跳转到登录界面
	@RequestMapping("/toLogin")
	public String toLogin() {
		return "login";
	}
	
	// 退出登录
	@RequestMapping(value = "/logout.action")
	public String logout(HttpSession session) {
	    // 清除Session
	    session.invalidate();
	    // 重定向到登录页面的跳转方法
	    return "redirect:toLogin";
	}

	

}
